<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="categoryAddForm" name="form-config-add">
        <input type="hidden" name="categoryId" th:value="${category.categoryId}">
        <div class="form-group">
            <label class="col-sm-3 control-label">名称：</label>
            <div class="col-sm-8">
                <input id="categoryTitle" name="categoryTitle" class="form-control" type="text" th:value="${category.categoryTitle}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">描述：</label>
            <div class="col-sm-8">
                <textarea name="description" class="form-control" th:text="${category.description}"> </textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">权重：</label>
            <div class="col-sm-8">
                <input id="configValue" name="weight" class="form-control" type="number" th:value="${category.weight}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">推荐：</label>
            <div class="col-sm-8">
                <div class="onoffswitch">
                    <input type="checkbox"  th:checked="${category.support == '1' ? true : false}" class="onoffswitch-checkbox" id="support">
                    <label class="onoffswitch-label" for="support">
                        <span class="onoffswitch-inner"></span>
                        <span class="onoffswitch-switch"></span>
                    </label>
                </div>
            </div>
        </div>
        <div class="mail-body text-center tooltip-demo">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i
                    class="fa fa-check"></i>保 存
            </button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i
                    class="fa fa-reply-all"></i>关 闭
            </button>
        </div>
    </form>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
    var prefix = ctx + "blog/category";

    $("#categoryAddForm").formValidate({
        rules: {
            categoryTitle: {
                required: true,
                rangelength: [2, 15],
            },
            description: {
                required: true,
                rangelength: [2, 80]
            },
            weight: {
                required: true,
                number: true
            },
        },
        messages: {
            "categoryTitle": {
                required: "请输入标题",
                rangelength: "请输入长度为 {0} 至 {1} 之间的标题",
                remote: "标题已存在"
            },
            "description": {
                required: "请输入标题",
                rangelength: "请输入长度为 {0} 至 {1} 之间的标题"
            },
            "weight": {
                required: "请输入权重",
                rangelength: "请输入正确格式的权重"
            },
        },
    });

    function submitHandler() {
        if ($.validate.form()) {
            var support = $("input[id='support']").is(':checked') == true ? 1 : 0;
            var data = $('#categoryAddForm').serializeArray();
            data.push({"name": "support", "value": support})
            $.operate.saveTabPut(prefix + "/edit", data);
        }
    }
</script>
</body>
</html>
